package cn.yyh.serviceOrg.controller;


import cn.yyh.commons.utils.R;
import cn.yyh.serviceOrg.entity.Shop;
import cn.yyh.serviceOrg.entity.dto.ShopVO;
import cn.yyh.serviceOrg.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yang
 * @since 2021-07-10
 */
@RestController
@RequestMapping("/serviceOrg/shop")
public class ShopController {
    @Autowired
    private ShopService shopService;

    @GetMapping("listAll")
    public R listAll() {
        try {
            List<Shop> list = shopService.listAll();
            return R.oK().data("rows", list);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("list")
    public List<Shop> list() {
        try {
            return shopService.listAll();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @PostMapping("register")
    public R shopRegister(@RequestBody ShopVO shop) {
        try {
            shopService.save(shop);
            return R.oK();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error().message(e.getMessage());
        }
    }
}

